//
//  RBTagContainerView.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/11.
//

#import "RBTagContainerView.h"
#import <UIView+YYAdd.h>

@implementation RBTagContainerView

- (void)addTagViews: (NSArray *)views
{
    [self removeAllSubviews];
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat itemH = 0;
    for (NSInteger i = 0; i < views.count; i++)
    {
        UIView *itemView = views[i];
        [self addSubview:itemView];
        itemView.width = MIN(itemView.width, self.constraintWidth);
        if(x != 0 && x + self.hMargin + itemView.width > self.constraintWidth)
        {
            x = 0;
            y += self.vMargin + itemView.height;
        }
        if (x != 0)
        {
            x += self.hMargin;
        }
        itemView.left = x;
        itemView.top = y;
        x += itemView.width;
        itemH = itemView.height;
    }
    self.calulatedHeight = y + itemH;
}

@end
